<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    @import "link.html"

</head>
<body>
<div class="">
    <div class="form">
        <form id="ff">
            <div class="item-box">
                <div class="input-item">
                    <label>
                        <em>旧密码:</em>
                        <input id="old-psw" name="old_psw" class="easyui-textbox" data-options="required:true,validType:'minLength[6,18]'">
                        <span class="tip-txt">请输入原密码</span>
                    </label>
                </div>
                <div class="input-item">
                    <label>
                        <em>新密码:</em>
                        <input id="new-psw" name="new_psw" class="easyui-textbox" data-options="required:true,validType:'minLength[6,18]'">
                        <span class="tip-txt">密码至少6个字符,最多18个字符！</span>
                    </label>
                </div>
                <div class="input-item">
                    <label>
                        <em>重复密码：</em>
                        <input id="repeat-psw" class="easyui-textbox">
                    </label>
                </div>
            </div>
            <input id="submit-btn" type="submit" hidden>
        </form>
    </div>
</div>

<script>
  $(function () {
    $.extend($.fn.validatebox.defaults.rules, {
      equals: {
        validator: function(value,param){
          return value === param[0].val();
        },
        message: '两次输入的密码不同！'
      },
      minLength: {
        validator: function(value, param){
          return value.length >= param[0] && value.length <= param[1];
        },
        message: '密码至少{0}个字符,最多{1}个字符！'
      }
    });

    $('#repeat-psw').textbox({
      required: true,
      validType: 'equals[$("#new-psw")]'
    });

    var loading=0;
    $('#ff').form({
      url: '../assets/json/area.json',
      onSubmit: function () {
        var isValid = $(this).form('validate');
        if (isValid) {
          loading=layer.load(1);
        }
        return isValid;
      },
      success: function (res) {
        var data=1;
        if(data===1){ //假设等于1是成功
          layer.close(loading);
          layer.msg('提交成功', {
            icon: 6,
            time: 1000
          }, function(){
            dialogClose();
          });
        }else {
          layer.close(loading);
          layer.msg('提交失败，请稍后重试',{icon:'2',anim:'6'}, function(){
            console.log('失败');
          });
        }
      }
    })

  });
</script>
</body>

</html>